package com.scc.persistence;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.stereotype.Repository;

import com.scc.entites.DishEntity;

@Repository("dishSetupDAO")
public class DishSetupDAO extends GenericDAO<DishEntity> implements IDishSetupDAO
{
   private SessionFactory sessionFactory;

   public DishEntity createDish(DishEntity entity)
   {
      Session session = getSessionFactory().getCurrentSession();
      session.save(entity);
      return entity;
   }
   
   public DishEntity getDish(String code)
   {
      DishEntity entity = getByCode(code, getSession());
      return entity;
   }
   
   public DishEntity getFirst()
   {
      DishEntity entity = getFirst(getSession());
      return entity;
   }
   
   public List<DishEntity> getAllDishes()
   {
      List<DishEntity> all = getAll(getSession());
      return all;
   }
   
   @Override
   public void updateDish(DishEntity entity)
   {
      Session session = getSessionFactory().getCurrentSession();
      session.update(entity);
   }

   @Override
   public void deleteDish(DishEntity entity)
   {
      Session session = getSessionFactory().getCurrentSession();
      session.delete(entity);
   }

   public SessionFactory getSessionFactory()
   {
      return sessionFactory;
   }
   
   private Session getSession()
   {
      return getSessionFactory().getCurrentSession();
   }
   
   @Resource(name="sessionFactory")
   public void setSessionFactory(SessionFactory sessionFactory)
   {
      this.sessionFactory = sessionFactory;
   }
   
}
